Add process configs endpoints for duplicate and getMetadata#74
Add process configs endpoints for duplicate and getMetadata#74carojeandat wants to merge 8 commits intomainfrom
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdded two endpoints to ProcessConfigController: GET /v1/process-configs/metadata to fetch metadata for multiple process configs by IDs, and POST /v1/process-configs/duplication to duplicate a process config by UUID. Service methods and unit tests supporting both behaviors were added. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Controller as ProcessConfigController
participant Service as ProcessConfigService
participant Repo as ProcessConfigRepository
participant DB as Database
Client->>Controller: POST /v1/process-configs/duplication?duplicateFrom={uuid}
Controller->>Service: duplicateProcessConfig(sourceUuid)
Service->>Repo: findById(sourceUuid)
Repo->>DB: SELECT process_config
DB-->>Repo: ProcessConfigEntity
alt Source Found
Repo-->>Service: Optional(ProcessConfigEntity)
Service->>Service: map entity -> ProcessConfig DTO, prepare duplicate
Service->>Repo: save(newEntity)
Repo->>DB: INSERT process_config
DB-->>Repo: Saved entity (id=newUuid)
Repo-->>Service: Saved entity
Service-->>Controller: Optional(newUuid)
Controller-->>Client: 200 OK + newUuid
else Source Not Found
Repo-->>Service: Optional.empty
Service-->>Controller: Optional.empty
Controller-->>Client: 404 Not Found
end
Suggested Reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java`:
- Around line 153-165: Update the test duplicateSecurityAnalysisConfig() in
ProcessConfigControllerTest to assert the response body contains the returned
UUID: after the mockMvc.perform(...) call, add an expectation that the response
content equals newProcessConfigId.toString() (e.g.,
andExpect(content().string(newProcessConfigId.toString()))), keeping the
existing status assertion and the verify of
processConfigService.duplicateProcessConfig(any(UUID.class)).
In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java`:
- Around line 147-153: The two empty test methods in ProcessConfigServiceTest
must exercise the service method duplicateProcessConfig: implement one test
(duplicateSecurityAnalysisConfig) that sets up a mock repository to return an
existing ProcessConfig when findById(...) is called, invokes
ProcessConfigService.duplicateProcessConfig(id), asserts the returned Optional
contains a new UUID different from the source id, and verifies
repository.save(...) was called with an entity that copies the relevant fields
from the source (name, settings, etc.) but has a new id; implement the second
test (duplicateSecurityAnalysisConfigNotFound) to have the repository return
Optional.empty(), call duplicateProcessConfig(id), and assert Optional.empty()
is returned and repository.save(...) is never called. Ensure you reference the
service method duplicateProcessConfig and repository.save/findById in the mocks
and assertions to validate behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b3677d95-3cac-4002-97a4-e08181bc7048
📒 Files selected for processing (4)
monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/ProcessConfigController.javamonitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.javamonitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.javamonitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java
...rver/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java
Show resolved
Hide resolved
.../test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java`:
- Around line 69-73: duplicateProcessConfig currently calls
processConfigRepository.save(sourceEntity) which will merge the existing entity
instead of inserting a new row; change the logic in ProcessConfigService. In
duplicateProcessConfig(UUID) fetch the source via
processConfigRepository.findById, create a new ProcessConfig instance (or
deep/shallow copy relevant fields from sourceEntity) and ensure its id is
null/cleared (and detach/avoid using the same entity instance), then call
processConfigRepository.save(newEntity) so JPA inserts a new record and returns
a new UUID; also copy or reset any relationship IDs, audit fields, or unique
constraints as appropriate before saving.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9f0a8841-eb67-4643-aea9-4f44d1ec4428
📒 Files selected for processing (3)
monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.javamonitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.javamonitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java
✅ Files skipped from review due to trivial changes (1)
- monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
- monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java
.../src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java
Show resolved
Hide resolved
There was a problem hiding this comment.
🧹 Nitpick comments (1)
monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java (1)
170-192: Test uses a mock entity and doesn't verify that fields are correctly copied.Using
mock(SecurityAnalysisConfigEntity.class)at line 176 returns an entity where all getters returnnull(or default values). This means the test doesn't verify that the duplication logic correctly copies fields from the source entity to the new one.The
ArgumentCaptoris created (line 190) but never used to assert the saved entity's fields. Compare this tocreateSecurityAnalysisConfig(lines 77-81) which verifies the saved entity's fields.♻️ Suggested improvement to verify duplication behavior
`@Test` void duplicateSecurityAnalysisConfig() { UUID processConfigId = UUID.randomUUID(); UUID expectedNewProcessConfigId = UUID.randomUUID(); + SecurityAnalysisConfigEntity sourceEntity = securityAnalysisConfigMapper.toEntity(securityAnalysisConfig); + sourceEntity.setId(processConfigId); + when(processConfigRepository.findById(processConfigId)) - .thenReturn(Optional.of(mock(SecurityAnalysisConfigEntity.class))); + .thenReturn(Optional.of(sourceEntity)); when(processConfigRepository.save(any(SecurityAnalysisConfigEntity.class))) .thenAnswer(invocation -> { SecurityAnalysisConfigEntity entity = invocation.getArgument(0); entity.setId(expectedNewProcessConfigId); return entity; }); Optional<UUID> newProcessConfigId = processConfigService.duplicateProcessConfig(processConfigId); assertThat(newProcessConfigId).isPresent(); assertThat(newProcessConfigId.get()).isEqualTo(expectedNewProcessConfigId); verify(processConfigRepository).findById(processConfigId); ArgumentCaptor<SecurityAnalysisConfigEntity> captor = ArgumentCaptor.forClass(SecurityAnalysisConfigEntity.class); verify(processConfigRepository).save(captor.capture()); + + SecurityAnalysisConfigEntity savedEntity = captor.getValue(); + assertThat(savedEntity.getSecurityAnalysisParametersUuid()).isEqualTo(securityAnalysisConfig.securityAnalysisParametersUuid()); + assertThat(savedEntity.getModificationUuids()).isEqualTo(securityAnalysisConfig.modificationUuids()); + assertThat(savedEntity.getLoadflowParametersUuid()).isEqualTo(securityAnalysisConfig.loadflowParametersUuid()); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java` around lines 170 - 192, The test duplicateSecurityAnalysisConfig uses mock(SecurityAnalysisConfigEntity.class) which yields empty/default getters so it doesn't verify field copying; replace the mock with a real SecurityAnalysisConfigEntity instance populated with representative field values (set the fields the duplication logic should copy), continue stubbing processConfigRepository.save(...) to assign expectedNewProcessConfigId, then use the existing ArgumentCaptor<SecurityAnalysisConfigEntity> captor from verify(processConfigRepository).save(...) and add assertions that captor.getValue() contains the same field values as the original entity (and that its id is the new UUID if applicable) to validate duplication semantics in ProcessConfigService.duplicateProcessConfig.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java`:
- Around line 170-192: The test duplicateSecurityAnalysisConfig uses
mock(SecurityAnalysisConfigEntity.class) which yields empty/default getters so
it doesn't verify field copying; replace the mock with a real
SecurityAnalysisConfigEntity instance populated with representative field values
(set the fields the duplication logic should copy), continue stubbing
processConfigRepository.save(...) to assign expectedNewProcessConfigId, then use
the existing ArgumentCaptor<SecurityAnalysisConfigEntity> captor from
verify(processConfigRepository).save(...) and add assertions that
captor.getValue() contains the same field values as the original entity (and
that its id is the new UUID if applicable) to validate duplication semantics in
ProcessConfigService.duplicateProcessConfig.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fb6a5a71-e32c-4535-bf4b-f85b234090df
📒 Files selected for processing (5)
monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/ProcessConfigController.javamonitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/MetadataInfos.javamonitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.javamonitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.javamonitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java
✅ Files skipped from review due to trivial changes (1)
- monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/MetadataInfos.java
🚧 Files skipped from review as they are similar to previous changes (1)
- monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java
| } | ||
|
|
||
| @Test | ||
| void duplicateSecurityAnalysisConfig() throws Exception { |
There was a problem hiding this comment.
add a use case where the process config is not securityAnalysis
There was a problem hiding this comment.
Actually, the type of ProcessConfig is never specified in this test, so it applies to any type. I renamed the test from duplicateSecurityAnalysisConfig to duplicateProcessConfig.
|



PR Summary
New endpoints to duplicate a ProcessConfig and to get its metadata (the processType)